package com.zhou.JavaAndroidFirm.app;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import com.zhou.JavaAndroidFirm.R;
import com.zhou.JavaAndroidFirm.base.BaseApplication;


/**
 * 封装Toast工具类
 * Created by Huang Mingfei on 2017/9/20 0020.
 */

public class AppToast {


    private static Toast toast;

    private static Toast initToast(CharSequence message, int duration) {
        if (toast == null) {
            toast = Toast.makeText(BaseApplication.getAppContext(), message, duration);
        } else {
            toast.setText(message);
            toast.setDuration(duration);
        }
        return toast;
    }

    private AppToast() {
    }

    /**
     * 左右抖动动画
     */
    public static void shake(View view) {
        Animation shake = AnimationUtils.loadAnimation(BaseApplication.getAppContext(), R.anim.home_item_shake);
        view.startAnimation(shake);
    }

    /**
     * @param text
     * @description
     */
    public static void showToast(String text) {
        initToast(text, Toast.LENGTH_SHORT).show();
    }

    /**
     * @param text
     * @param duration
     * @description
     */
    public static void showToast(String text, int duration) {
        initToast(text, duration).show();
    }

    /**
     * @param context
     * @param text
     * @param duration
     * @description
     */
    public static void showToast(Context context, String text, int duration) {
        initToast(text, duration).show();
    }

    /**
     * 自定义显示Toast时间
     *
     * @param context
     * @param strResId
     * @param duration
     */
    public static void show(Context context, int strResId, int duration) {
        initToast(context.getResources().getText(strResId), duration).show();
    }


}

